Page({

  /**
   * 页面的初始数据
   */
  data: {
    fbsongyang:[],
    region: ['广东省', '全国', '海珠区'],
    pagenum:1,
    array: ['全部','狗狗', '猫咪', '兔子', '鼠类','其他'],
    index:0,
    nextpage:null,
    topname: '宠物领养',
    prepage: 1,
    height:180
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: 'https://www.cwlyz.com/wx/Index/lylist', 

      data: {
        x: '',
        y: ''
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res);
        that.setData({ fbsongyang: res.data.data });
        that.setData({ nextpage: res.data.nextpage });
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  
  bindRegionChange: function (e) { //城市选择
    var index = e.currentTarget.dataset.index;
    this.setData({
      region: e.detail.value,
      index:index,
    })
    var that = this;
    wx.request({
      url: 'https://www.cwlyz.com/wx/Index/lylist',
      data: {
        area: e.detail.value[1],
        index: index,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data.data);
        that.setData({ fbsongyang: res.data.data });
        that.setData({ nextpage: res.data.nextpage });
        that.setData({ pagenum: 1 });
      }
    })
  },
  scrolltolower :function(){
    console.log(1111);
  },
  moreinfos:function(event){ //点击更多
    console.log(this.data.pagenum);
    var that = this;
    var pagenum=event.currentTarget.dataset.pagenum;
    var address = event.currentTarget.dataset.address;
    var index = event.currentTarget.dataset.index;
    this.setData({ pagenum: pagenum+1});
    wx.request({
      url: 'https://www.cwlyz.com/wx/Index/lylist',

      data: {
        pagenum: pagenum,
        area: address,
        index: index,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var fbsongyang = that.data.fbsongyang;
        var sysinfo = res.data.data;
        var fbsongyangnew = fbsongyang.concat(sysinfo);
        that.setData({ fbsongyang: fbsongyangnew });
        that.setData({ nextpage: res.data.nextpage });
      }
    })
  },
  bindPickerChange: function (e) { //种类选择
    this.setData({
      index: e.detail.value,
      area : e.currentTarget.dataset.address,
    })
    var that = this;
    var index = e.detail.value;
    var area = e.currentTarget.dataset.address;
 
    wx.request({
      url: 'https://www.cwlyz.com/wx/Index/lylist',
      data: {
        area: area,
        index:index,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res);
        var sysinfo = res.data.data;
        that.setData({ fbsongyang: sysinfo });
      }
    })
  },
  listinfo:function(e){
    var syid=e.currentTarget.dataset.syid;
    var sytype=e.currentTarget.dataset.sytype;
    if(sytype==2){
      wx.showToast({
        title: '已经送养了！',
        image: '/images/meiyou.png'
      })
      return;
    }
    if (sytype == 0) {
      wx.showToast({
        title: '正在审核中...',
        image: '/images/shzt.png'
      })
      return;
    }
    if (sytype==1){
             wx.navigateTo({
               url: '/pages/details/details?id=' + syid,
             })
    }
  }
})